<?php
require_once dirname(dirname(dirname(__FILE__))).'/kw_base.php';

$data = $sql->select(array(
    'table'   => 'kw_user', 
    'where'  => array('uid = 1')
    ));
$username = $data[0]['username'];
$password = $data[0]['password'];

if (isset($_COOKIE['kw_token'])) {
  $token = $_COOKIE['kw_token'];
  if ($token == md5($username).'_'.$password) {
    //重定向浏览器
    Header("Location:pageMng.php");
    //确保重定向后，后续代码不会被执行
    exit;
  }
}
if (isset($_POST['login'])) {
  if ($_POST['user'] == $username 
  && md5($_POST['pass']) == $password) {
    setcookie('kw_token', md5($username).'_'.$password);
    //重定向浏览器
    Header("Location:pageMng.php");
    //确保重定向后，后续代码不会被执行
    exit;
  }
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>后台管理</title>
<link rel="stylesheet" href="css/style.css" type="text/css" />
</head>
<body>
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
  <div id="login_title">登录后台</div>
  <div id="login_form">
    <div id="login_form_box">
      <div class="label">帐号</div>
      <div class="textbox"><input name="user" type="text" /></div>
      <div class="label">密码</div>
      <div class="textbox"><input name="pass" type="password" /></div>
      <div class="bottom"><input name="login" type="submit" value="登录" class="button" /></div>
    </div>
  </div>
</form>
</body>
</html>
<?php
  $sql->disconnect();
?>